{% extends "main.html" %} 

{% block title %}--admin{% endblock %}

{% block blog %}             
<script type="text/javascript">
function $(id){return document.getElementById(id)}
function newcategory(){
  if(document.getElementById("singleton")){
    alert("only one form here!")
    return;
  }
  var tr = document.createElement('tr')
  var td = document.createElement('td')
  td.innerHTML = '<form id="singleton" method="post"><input type="text" name="name" size="50" /><input type="submit" value="add" /></form>'
  tr.appendChild(td)
  $('ncategory').appendChild(tr)
}
function rpc(action){
  ajaxObject = function() {
    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){
    try { return new XMLHttpRequest(); } catch(e){
    throw new Error( "This browser does not support XMLHttpRequest." );
  }}}}
  var ajax = new ajaxObject(); // use ajaxObject to start XMLHttpRequest() for most browsers  
  ajax.onreadystatechange = function(){
    if(ajax.readyState < 4){$(action).innerHTML="building";}
    if(ajax.readyState == 4&& ajax.status == 200){
       $(action).innerHTML=ajax.responseText;}}
  pwurl = "/rpc?action="+action;  
  try{ajax.open("POST",pwurl,true);} catch(e){alert(e);}
  ajax.setRequestHeader("Content-length", 0); 
  ajax.send('');
}
</script>
    <div id="postpath"><a title="Goto homepage" href="/">Home</a> &gt; Admin</div>
		<div class="post"><h2>Categories:</h2>
		<div class="content">		 
		  <table><tbody id="ncategory" style="width:90%">
		    <tr><th style="width:50em">Name</th><th>Num</th></tr>
		    {%for category in categories%}
		    <tr><td>{{category.name|unquote}}</td><td>{{category.num}}</td></tr>
		    {%endfor%}
		  </tbody></table>
		  <a href="javascript:newcategory()">add new category</a>
	  </div>
	  </div>
		<div class="post">
		 <h2>memcache statistics:</h2>
		  <div class="content">
  		  <table><tbody id="ncategory" style="width:90%">
  		    <tr><th style="width:50em">Name</th><th>Num</th></tr>
          <tr><td>Number of cache get requests resulting in a cache hit.</td><td>{{cache_stats.hits}}</td></tr>
          <tr><td>Number of cache get requests resulting in a cache miss.</td><td>{{cache_stats.misses}}</td></tr>
          <tr><td>Sum of bytes transferred on get requests. Rolls over to zero on overflow.</td><td>{{cache_stats.byte_hits}}</td></tr>
          <tr><td>Number of key/value pairs in the cache.</td><td>{{cache_stats.items}}</td></tr>
          <tr><td>Total size of all items in the cache.</td><td>{{cache_stats.bytes}}</td></tr>
          <tr><td>Oldest_item_age: how long a new item will survive in the cache without being accessed.</td><td>{{cache_stats.oldest_item_age}}</td></tr>
          <tr><td id="flushall">flush all</td><td><button  onclick="rpc('flushall')">flashall</button></td></tr> 
  		  </tbody></table>		 
	   </div>
	  </div>
	  <div class="post">
  	  <h2>Ruilding:</h2>
  		  <div class="content">
    		  <table><tbody id="ncategory" style="width:90%">
    		    <tr><th style="width:50em">Items</th><th>Action</th></tr>
            <tr><td id="rbcategories">Categories</td><td><button  onclick="rpc('rbcategories')">BeBuild</button></td></tr>
            <tr><td id="rbtags">Tags</td><td><button  onclick="rpc('rbtags')">BeBuild</button></td></tr>
            <tr><td id="rbarchives">Arhives</td><td><button  onclick="rpc('rbarchives')">BeBuild</button></td></tr>
    		  </tbody></table>		 
  	   </div>
  	 </div>
{% endblock %}